﻿'use strict';
app
    // Login Box controller 
    .controller('ForGotSecondPassController', [
        '$rootScope', '$scope', '$state', '$localStorage', '$http', '$modal', function ($rootScope, $scope, $state, $localStorage, $http, $modal) {
            $scope.User = { Sponsor: '', UserName: '', Email: '', Password: '', Password2: '' },
            $scope.popup = function (windowClass) {
                $modal.open({
                    windowClass: windowClass,
                    templateUrl: "WarningModal",
                    controller: "ForGotPassModalInstanceCtrl",
                    size: "sm",
                    resolve: {
                        messeger: function () {
                            return $scope.messeger;
                        },
                        title: function () {
                            return $scope.title;
                        }
                    }
                })
            },
            $scope.doPincode = function (UserName, email) {
                $http.post($rootScope.APIUrl + 'ForgotSecondPass', { username: UserName, mail: email }).then(
                    function successCallback(resp) {
                        $scope.messeger = resp.data.Messeger,
                        $scope.title = "Forgot Password Level 2",
                        $scope.popup("modal-message modal-warning");
                        if (resp.data.Status) {
                            $localStorage.MailPinCode = email;
                            $state.go('login');
                        }
                    }, function errorCallback(resp) {
                        if (resp.status == 0) {
                            $scope.checkSponsor = 0,
                            $scope.messeger = "Contact the Administrator by supporting",
                            $scope.title = "ForGotPass",
                            $scope.popup("modal-message modal-warning");
                        }
                    })
            }
        }
    ])
app.controller('ForGotPassModalInstanceCtrl', function ($scope, $modalInstance, messeger, title) {
    $scope.messeger = messeger;
    $scope.title = title;
    $scope.ok = function () {
        $modalInstance.close();
    };
    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    };
});